define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/overlord/meal/order/index' + location.search,
                    // add_url: 'user/overlord/meal/order/add',
                    // edit_url: 'user/overlord/meal/order/edit',
                    // del_url: 'user/overlord/meal/order/del',
                    multi_url: 'user/overlord/meal/order/multi',
                    import_url: 'user/overlord/meal/order/import',
                    table: 'user_overlord_meal_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'user.nickname', title: __('用户昵称'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        //{field: 'platform', title: __('Platform'), operate: 'LIKE'},
                        {field: 'shop_name', title: __('Shop_name'), operate: 'LIKE'},
                        {field: 'shop_logo', title: __('Shop_logo'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},

                        {field: 'expire_reason', title: __('Expire_reason'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'ratio', title: __('Ratio'), operate:'BETWEEN'},
                        //{field: 'maxCommission', title: __('Maxcommission'), operate:'BETWEEN'},
                       // {field: 'mediaRatio', title: __('Mediaratio'), operate:'BETWEEN'},
                        //{field: 'mediaMaxCommission', title: __('Mediamaxcommission'), operate:'BETWEEN'},
                        //{field: 'status', title: __('Status'), searchList: {"10":__('Status 10')}, formatter: Table.api.formatter.status},
                        {field: 'audit_status', title: __('审核状态'), searchList: {"0":__('待审核'),"1":__('审核通过'),"2":__('审核拒绝')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'expired_time', title: __('Expired_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order_id', title: __('Order_id'), operate: 'LIKE'},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'pay_time', title: __('支付时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'poiEventId', title: __('Poieventid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'totalCommission', title: __('Totalcommission'), operate:'BETWEEN'},
                        {field: 'userCommission', title: __('Usercommission'), operate:'BETWEEN'},
                        //{field: 'expectedCashbackTime', title: __('Expectedcashbacktime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'wxAppid', title: __('Wxappid'), operate: 'LIKE'},
                        //{field: 'wxPath', title: __('Wxpath'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'feedback_images', title: __('Feedback_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        //{field: 'complete_time', title: __('Complete_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'send_time', title: __('Send_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'planActivityType', title: __('Planactivitytype')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'audit',
                                    text: __('审核通过'),
                                    confirm:'确认审核通过该评价吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'user/overlord/meal/order/pass',
                                    visible:function(row){
                                        if(row.audit_status == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'refuse',
                                    text: __('审核拒绝'),
                                    confirm:'确认审核拒绝该评价吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-danger btn-xs btn-detail  btn-ajax',
                                    url: 'user/overlord/meal/order/refuse',
                                    visible:function(row){
                                        if(row.audit_status == 0){
                                            return true;
                                        }
                                    }
                                },
                            ],
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
